I copied/pasted your code as shown here and ran it on my Windows XP. It runs just fine for me. (I typed "LPT1" as my printer port; however, your printer may not be on LPT1.)
Many thanks for trying it on your PC
and letting me know what happened.
I think that the port may be an issue since my printer
is attached to a USB port which is described as a
Virtual Printer Port for USB.
I shall try some more with a printer attached to LPT1