My code assumes the LED will be lit up when the GPIO pin is high. It's possible you have it the opposite way. You mentioned connecting to the 5V pin through a resistor. That means you turn on the LED by bringing the GPIO low. If that's right, it may not work correctly. Anyway, the code works on my Nano using a transistor, so I don't know what's wrong.
Also, the code runs as soon as the Arduino is powered up. So you might try hitting the reset button.
And you are using D10, right?