I think the worst part about this bug is how the script is being called to execute what's going on. I understand the attempt with this script, but there's no call to the actual sim the script is supposed to target after executing. Here's a description of how the script works with examples and what it should be doing instead.
The script will attempt to call an NPC sim that someone in the household has a relationship with to target a current household sim to ask to be BFF or Prom Date. (Now I'm not sure if these are separate scripts or if it's all coded as one, but I see these as the only two situations that have happened to me in my 4th generation play right now.) The NPC will then spawn on lot, ignore all door lock settings and walk up to the currently selected sim (the one you are giving commands to when the script executes) and ask them to either be BFF or Prom Date (whichever the script has chosen to execute).
What this creates is a situation where NPC sims with no relationship with the selected sim are creating these awkward situations. To use as an example from my current game: My current play (fresh game since High School release) is on generation 4 with two, now elder parents, and two teens. I play full autonomy while turning off autonomy for the selected sim. I then play the heir of the family until he/she becomes elder at which time I switch over to the new heir(ess). The oldest teen (female) has a high school crush (male) and often times invites him over after class. They socialize and have created a strong friendship, yet they haven't started romance on their own. Since the father of the household is now elder I play as the son who is the heir. While playing as him I had an encounter with my sisters crush showing up at the house, marching straight into the kitchen and asking me to prom. Of course I told him no and had to deal with the negative moodlet while around this sim now. I have no relationship with this person and know him simply as the guy my sister has a crush on. Boy she must be upset that her crushed me to prom instead of her. BTW, I had just blown out the candles on my cake to become a teen. That NPC moved quick to hit on me; kind of creepy.
Second scenario is very similar and what most people are seeing. While playing as the teen son my, now dead and totally a ghost, uncle barged into the house and asked that we be BFFs. Odd thing to have happen since he had no relationship with this uncle while growing up due to his father and uncle never getting along as kids and having a bad relationship until recently as it faded back to non-existent. Yet here he is, my NPC uncle, whom I have never met in my entire life wants to be my BFF.
The script error is simple. Instead of spawning the NPC and telling them which sim they are supposed to interact with, the script spawns the NPC and tells them to target the active sim. An easy fix to this would be something similar to how NPC neighbors or friends will show up, knock on the door and say something like "Hey, I have a gift for you", or whatever it says. In this situation the script needs a variable added to include the proper target sim. The NPC then needs to spawn, knock of the door and say perhaps "I have something important I want to ask you". Then when you invite them in, no matter which sim invites the NPC in, they can continue their command to ask the proper household sim to be BFFs or Prom Date.
Simple, easy, done. Not rocket science, just simple scripting. Not trying to do your job, just pointing out things that should have been addressed in development and should definitely have been caught and fixed in testing (that's if you even test your scripts).