Man nearly hit by train