Improved cgi-handler output construction

Also added cgi-handler test (see tests/test-env1.scm, tests/env.scm)