in reply to different output from gzwrite

You should read What's wrong with always quoting "$vars" ?
print "$var"; # BAD $new = "$old"; # BAD somefunc("$var"); # BAD