in reply to Cookies write to screen, not to cookie file

As others have said, CGI and CGI::Cookie are perfect for this.

It sounds suspiciously like a buffered-output problem, where one module is buffering the output to be sent to STDOUT on completion of the script, and you're subverting the purity of the HTTP headers by issuing a print statement before it's time.

It also could be, as others have said, that you're not placing the "\r\n" after the cookie header.

Unless you're writing your own one-off modules to learn more about the CGI interface, in general, please, please, please use the various CGI modules; they're well tested and make writing secure CGI scripts if not simple, then at least attainable for a novice.