Redirect the output in a file and on screen

I am trying to get following result from the scipt I have. First time it generates the o/p in correct format. However if I run it again it appends to the existing file. I would like to see o/p on screen as well as save it in file. Everytime it should create new file.

## I/P file
0174
0175
0176
0177

## O/P file as well as on screen

create grp 0174, class=first;
new mem 14F4 to grp 0174;
new mem 14F5 to grp 0174;
new mem 14F6 to grp 0174;
new mem 14F7 to grp 0174;
new mem 14F8 to grp 0174;

 
     $grphd = `head -1 < $formember`;
     chomp ($grphd);
     $class="first";
     $memout = "/tmp/$class\_grp\_$grphd";
     $totcnt = `wc -l < $listmem`;
     $memcnt1 = 1;
     open (STDOUT, "| tee -ai $memout");
     open (FORMOUT,  $listmem) || die "Form Meta - Can't open $memdevlst: $!\n";
 while ($MEM= <FORMOUT>)
        {
if (($totcnt > 1) && ($metmcnt1 =~ 1))
        {
        chomp $MEM;
        print "create grp  $MEM, class=$class; \n";
        $memcnt1++;
        }
else
        {
        chomp $MEM;
        print "add dev $MEM to meta $grphd;\n";
        $memcnt1++;
        }
}
}
close (FORMOUT);
close (STDOUT);

In shell script i would use tee command for this purpose. Sorry no PERL.... :frowning:

You've used the -a option for tee which appends instead of overwrites the file

what is the alternative option. I don't like using STDOUT it directs everything to that file.