"^M: Command not found" from script
cat -v script
shows you that at least some of the lines have a CR (carriage return) character, probably at the end.
Your script is a text file in DOS/Windows format. You need to convert it to Unix format (i.e. remove the CRs). This can be done by editors or e.g. the tool dos2unix
.