in reply to sprintf is printing unexepected output

I suspect there's a CR at the end of your string from the text file, one that didn't get removed by chomp. You could try printing to a file instead of to the console, and check its contents with a hex editor.

Try using

s/[\r\n]+$//
to get rid of any trailing CR+LF.