Start with this:
open(OUTPUT, "> test.txt")
or die "test.txt: $!";
print OUTPUT $_;
And see what's coming in on stdin. The problem should be much clearer, and CGI.pm is not the answer, since your input is not conformant with CGI standards.
: Ok, after re-reading your first post, I see that you've already tried this. Now I'll attempt to answer your questions directly. You have the right idea with that sample code, and no, CGI.pm won't help you one bit. You're not dealing with true CGI data. CGI.pm shouldn't be updated to deal with this, because your application isn't compliant with the CGI specifications, which, circularly, is why CGI.pm won't help you out.