...Fix the line... open my $fh, ">:encoding(cp1252)", "test.xml" or die $!; $doc->printToFileHandle($fh);