in reply to File writing script (taint mode problem?)

Try to test your perl-code in a shell with:
perl -cw myscript.pl
That might tell you something about not having declared $q...

Best regards,
perl -e "print a|r,p|d=>b|p=>chr 3**2 .7=>t and t"