in reply to Writing to a file

If you have apache server or something similar you can view his error log and access log, maybe it'll give you any clues about your problem, you can also use:
print CGI::Dump();
It'll print to your browser all the arguments the browser is sending to your CGI.
Try to work out what is your problem more specifically and maybe then someone could help you more (no one will read all the code you posted), goodluck

Hotshot