open(STDOUT, ">my_txt_output.txt"); my $fh = new IO::Handle(); $fh->fdopen( fileno( STDOUT ), "w" ); $pop->HeadAndBodyToFile( $fh, $i ); close STDOUT;