That's a good question. I've always wondered that too ever since one scared the tar out of me when I was a kid. It was during Halloween and the local boy scouts put on a haunted house. They sat you in a chair in the middle of a dark room, then played the sound of a locomotive full blast while moving a large spot light towards you. It had it's effect on this 10 year old!
Anyways, I found this link called, "The History and Evolution of the Railway Locomotive Headlamp,"
here. Hope it helps.