open my $out_fh, '>', $file; print {$out_fh} $doc->toString;