If anyone is curious, here are some test results based on your advice:
I downloaded and tried out
optiperl and, making sure to switch the files to "Unix Format", got exactly the same results as with textpad.
I ran
od -c on it, and it showed lots of \r\n pairs.
I then ran dos2unix on the file, and that fixed the file so it worked.
I then downloaded the file, changed its name, and uploaded it again. It still worked, so I don't think the problem is with the FTP client (which, incidentally, I run in "always ASCII" mode).
I also tried the -- switch, which made the script run too.
Incidentally, I have very good reasons for avoiding the -w switch, which you can read about
here if you are curious.
Thank you all for your advice. I have a working solution now, but no real understanding why my perl scripts are always created with \r\n pairs. I will try a couple more editors.