This is caused by the differences between Unix/Linux line-endings and windows line-endings. To terminate a line, Unix uses "\n" and windows uses "\r\n"; the extra \r shows up as a ^M when you view a file with windows line-endings on Unix.
Adding the following setting to your user settings should help (although I'm not sure if it will convert files already with windows line-endings):
To change the line endings of an existing file, try the dos2unix command in Unix, something like:
dos2unix -o your_file.xyz
Note: I would check out the man page of dos2unix before you execute this command (since it can overwrite your file).