It is possible that the dog escaped from his house without the owners knowing.
The dog was walking in front of you, as he was trying to "lead" you. One of my dogs, when we are in the woods I will sometimes let her off the leash as I know she will not run far. She runs up ahead, and waits for me to get close, then she will run up again. She does that over and over. I think she thinks she is the leader.
Our neighbor used to have a golden that would follow all the neighborhood kids around. He would be gone for hours, and would eventually find his way home either on his own, or in the back of a police car.
Anyway, Some dogs do that. It doesn't sound like the dog was threatening you, although I could see how that could be a bit intimidating to a non-dog person. I am not sure how you could keep the dog from following you though. The best you can do is to try to find the owner, and to loudly keep telling the dog to go home. If you have a cell phone, a call to the local PD would work too.