in reply to CGI printing output x times, where x is the number of forks.

When you run it from the shell, STDOUT is line buffered, but this is not the case when run by the web server, thus the children inherit the parent's output buffer. $| = 1; will fix the problem.