in reply to Escaping special chars to add in a file
printf NFILE "$item\n"; should be printf NFILE "%s\n", $item; or print NFILE "$item\n";
The "f" in "printf" stands for "format" (not "file"), and you didn't provide one.
Ref: print, printf