I have no idea if BB-8 knew who Rey was when it followed her.
But there are good reasons for BB-8 to follow Rey, even if it doesn’t know who she is:
She can stand up to the locals.
When Rey rescues BB-8 from Teedo, she doesn’t get much resistance. If there are people going around capturing droids, and you're a small and fairly defenceless droid, sticking with somebody who can defend you is a smart move.
Plus puppy dog instinct, following somebody who rescued it. Rey probably seems like a pretty nice person at that point.
She has local knowledge.
I don't remember exactly what she says, but it's something like:
Town is that way, stay off Kelvin ridge, avoid the quicksand in [location] or you'll get sucked in.
We learn two things: (1) this is a hazardous environment, and (2) Rey knows where the hazards are. BB-8 may not know much about the local geography – so it would be wise to stick with somebody who does.
It's a pretty big desert.
We don't know how far BB-8 has travelled before it meets Rey, but it could be a while. Jakku seems to be a pretty big and empty desert.
If you've travelled for miles without seeing another creature, you might want to stick with the first (friendly) one you find. That comes with a much bigger chance of meeting more people.
It's also not obvious to me what BB-8 might recognise in Rey to mark her out from another friendly scavenger.
- It doesn't seem like droids are Force-sensitive.
- She has no ties to the Resistance (at least not as an adult).
- If she's related to somebody that BB-8 knows, or it recognises her from some other context, it would be a little strange not to mention it.
I think BB-8 is just acting on instinct here.