... $R->startR; open FH, ">", "c:/scripts/test2.txt" or die $!; ... #### #!/usr/bin/perl use warnings; use strict; use Cwd; use Statistics::R; my $currentdir = cwd(); my $R = Statistics::R->new(); open FH, ">", "test1.txt" or die $!; $R->startR; $R->stopR; chdir($currentdir); open FH, ">", "test2.txt" or die $!;