The ^M is a carriage-return character. If you see this, you're probably looking at a file that originated in the DOS/Windows world, where an end-of-line is marked by a carriage return/newline pair, whereas in the Unix world, end-of-line is marked by a single newline.
Read this article for more detail, and also the Wikipedia entry for newline.
This article discusses how to set up vim to transparently edit files with different end-of-line markers.
If you have a file with ^M at the end of some lines and you want to get rid of them, use this in Vim:
:s/^M$//
(Press Ctrl+V Ctrl+M to insert that ^M.)