I use Compress::Zlib for a number of in-memeory (un)compressions. I don't have any examples on hand for generating a file (I store to a database), but I did do that in tests to be sure the compressed data in the db could alternately be SELECT'd to a file and uncompressed with gzip.
my $zipped_raw = Compress::Zlib::memGzip($raw_genome);
my $raw_genome = Compress::Zlib::memGunzip($zipped_raw);
So if you wanted to compress in memory and save to file based on your example:
$fu = "bla bla bla bla" ;
$ba = Compress::Zlib::memGzip( $fu ) ;
open FFF, ">ba.txt.gz" or die "$!" ;
print FFF $ba;
close (FFF) ;
However Compress::Zlib has methods that handle reading and writing gzip files built in.
Which you may want to look at first if that's all your after.