in reply to CGI http header error

You are writing to a local file and not sending any output to SDOUT. CGI programs expect a minimal output to STDOUT (including headers) so they can send some response to the browser.

Most likely you need to remove all references to the OUT file(handle) so your output gets returned to the browser.

-- Joost