Not a perl expert here, just a guess.
the test code may interfere with the FCGI file handle 0 or 1, so it breaks the FCGI protocol. It is not a problem with CGI though.
And it is really a bad idea to start another process for the compression, should use a Perl internal module if available. Or, not to compress it at all and let web server to do it.