This has been an issue for quite some time... Personally, I refer to it as the "squatters" bug. In my opinion it is one of the most problematic and intrusive issues in the game, and needs to immediately make its way to the top of EA's laundry list.
I've read in many places that it is somehow connected to Island Living, but I think the roommate system must be involved somehow as well since the sims in question act like they're roommates in the household and don't have the "ask sim to leave" social option. As a rotational player, I can assure you that it happens in every world of the game. Some things I've noticed is that these sims tend to show up if you have extra unclaimed beds in your house, but this isn't a hard and fast rule either and sometimes they'll show up when there aren't extra beds either. I've also noticed that sometimes, the sims showing up are aliens, but again, that isn't always the case.
Typically, if you travel to another lot, and then return to your home, they will usually be gone, but it doesn't take long for a new different random townie to show up and start squatting on your lot.
The door locks mentioned by @Beardedgeek are really the only work around that I've been able to find; however, even at that, if a sim thinks they're moving into your house, even after you've locked your door, they'll still stick around and live in your backyard for an extended period of time before finally leaving.
The door locks, while they solve the problem, are still kind of annoying because you have to unlock your door every time an invited guest comes over in order to let them in, lock it again once they're inside to keep others out, and then unlock it to let them leave, and lock it again afterwards... Frankly, its kind of annoying and we shouldn't have to do all that to solve the problem. It's also annoying as a rotational player, as if I forget to unlock the door before switching households, I can't visit that lot with another family because I've left the doors locked. This was a problem the other day when my paranormal investigator had an assignment at a house where I'd left the doors locked and I couldn't get in to do my job!