Are all the files (including the script itself) normal ASCII files?
It looks like the script might not be (the \r part).
The file command might not show the difference, try this instead:
If \r is shown instead of \n then it is not a regular ASCII file.