... my $outfile = '/path/to/file/to/create'; open my $fh, '>', $outfile or die "Cannot create $outfile, $!\n"; my $treeout = Bio::TreeIO->new(-format => 'newick', -fh => $fh); ... #### ... my $outfile = '/path/to/file/to/create'; my $treeout = Bio::TreeIO->new(-format => 'newick', -file => ">$outfile"); ...