in reply to Adding \n (new line) and removing \r in a file

Do you mean there is a "\r" at the end of the file and you want "\n" there instead? If so, how about changing "\r" to "\n" if it doesn't already precede "\n", and then deleting any "\r" that remains:
perl -i.bak -pe 's/\r(?!\n)/\n/g; tr/\r//d' test.dat
Or, if there is no "\r" at the end -- that is, you're deleting any/all "\r" in the file and adding "\n" at the end, add the "-l" option:
perl -i.bak -lpe 'tr/\r//d' test.dat
(but that might not do exactly what you want, depending on what OS you're running on)