in reply to IO::Compress::Gzip and unicode

As things stand you need to explicitly encode the data to utf8. To do that you need to use encode_utf8 rather than decode_utf8.

Change this line

print $fh $opts->{'data'};

to this

print $fh Encode::encode_utf8($opts->{'data'}) ;