Perhaps it was a Barghest or another demonic creature and you were saved by some good-natured outside intervention.

It sounds a bit weird though, if you twitched or so that would be more explainable, but taking several steps and closing a door is a bit much for an unintended action.

Maybe it wasn't a dog but a bear? And then you smelled it and subconsciously your lizard brain smelled 'bear' and made you run?