It's a good question. Early automobiles; and before that, wagons, had the driver seated on the right side as they ran down the right side of the road.
It was more important to pay attention to the shoulder than it was to watch the passing move...and there were no yellow traffic lines in those days.
The railroad, like the automobile, evolved out of the horse-and-Conestoga era. The operator (engineer) sat on the right. But since railroad equipment is fixed to the rails and doesn't need to be guided past opposing traffic...unlike with autos, engineers remained on the right.
UNVERIFIED STORY: The old Chicago North Western Railway was originally engineered by a British firm and as such, had traffic passing to the right, instead of to the left - like British highways. The engineer's throttle/brake/seatbox was on the LEFT side, opposite what every other American railroad did...I understand this remained the case right up until the Diesel Era and standardization.