I spent an entire day figuring this out recently. At least on the CERN server
you need to begin the name of the script with "nph-" (for No Parse Header).
This tells the server to connect the output of your program directly with the
requesting client rather than piping is through the server (which causes it
to buffer up).
If anyone is interested I've created a cgi script (actually it's a C program)
which lets you specify a server push animation with a simple text file which
contains gif filenames and delays in milliseconds. I know it works under
the CERN server, I don't know if it will work anywhere else.