If I execute above script, I get an error because print_to_file needs a filename as parameter, but after adding that, all runs as expected. So maybe you have a very old twig version (mine seems to be from 2007-11-13). Is print_to_file() mentioned in the man page of Twig? Can you find the subroutine print_to_file if you simply search the file XML/Twig.pm with grep (should be somewhere in /usr/lib/perl5 if you have a normal linux distribution)
If not, just get a newer version from CPAN.