Interesting story. Good for you for staying calm and defusing the situation by being polite and nonconfrontational. That isn't always easy to do when your heart is pounding and you know it was just an innocent mistake.
As you pointed out, it would have been better if you'd locked your door beforehand. Stuff happens, but that could have been a bad mistake.
You made absolutely the right decision by not opening the door yourself or getting out to talk to him. That could have been read as increasing the conflict.
I fixed the paragraph issue above. No worries.
My personal website: Cornered Cat