in reply to sprintf is printing unexepected output
I would suspect you have some funky control character in data.txt that you don't see through a normal editor. Is this on a *nix system or windows? Can you do an od -xa on data.txt?