I think you may have a carriage return character \r at the end of the lines in your input file. chomp doesn't remove it. So after $data with a \r gets printed the caret is at the beginning of the line and the beginning of the line is overwritten with whatever follows $data in the print statement.
You can remove \r with this for example tr/\015//d;.