(not a teacher...)
"I NEEDN'T HAVE BROUGHT that milk." By saying this you mean that bringing that milk was not necessary (in the past), or there wasn't any need for that, but you brought it. The opposite of this could be expressed by "You should have brought that milk" which means in the past it was necessary for you to bring it, but you idn't.
"I STOPPED TO GIVE my friend a lift." If after the verb "stop" the second verb is in an infinitive form it means that you were doing something, then you stopped and started a new activity. I your example you were driving when you saw a friend of yours, so you pulled over to give them a lift. However, if after "stop" the second verb comes with an "-ing" it means that you were doing something and you decided to give up doing the same thing. In your exampe, you used to give your friend a lift, say everyday, but you decided not to do that any longer.
So, "To stop to do Sth" = To stop because you want to do Sth new
"To stop doing Sth" = To quit doing Sth (that you no longer wish to continue.)
Student or Learner