Probably your problem is that you did not pass the file descriptor to a file reference.
$t->flush(\*OUT)
Some suggestions for your code: in modern perl, it is better to use three arguments to open and indirect file descriptors:
open (my $fh_out, '>', $out_file) or die "unable to open '$out_file' for writing: $!";
$twig->print($fh_out);
Another way to print is to bind your tree with $twig->sprintand print to a file as usual
print {$fh_out} $twig->sprint();
source
share