in reply to sprintf is printing unexepected output

Are you sure your open succeeded? Try:

open (IFH, "data.txt") or die "can't open: $!";

I believe the file is not being opened as you would expect, and then <IFH> is not bringing the content you want.

Update: Never mind -- the CRLF issue that so many monks pointed makes much more sense than my wild wrong guess.