Perl - save results to output file.

Can any one please help, the code works...I want the output of $result to be saved in an output.txt file which is lcoated in c:\\temp\\output.txt.

 
$filepath="C:\\temp\\ip.txt";
open (HOSTLIST,"$filepath"); 
@hosts=(<HOSTLIST>); 
 
foreach $host(@hosts) 
{ 
  $results = `nslookup $host`; 
  chomp ($host); 
  print ("Results for $host:\n"); 
  print ("$results\n\n");
} 
close (HOSTLIST);
use strict;
use warnings;

my $filepath = "ip.txt";
my $outfile  = "output.txt";

open (HOSTLIST, "$filepath") || die "ERROR: opening $filepath\n";
my @hosts = <HOSTLIST>;
close HOSTLIST;

open (OUTFILE, ">> $outfile") || die "ERROR: opening $outfile\n";

foreach my $host(@hosts)
{
   my $results = `nslookup $host`;
   chomp ($host);
   print OUTFILE "Results for $host:\n";
   print OUTFILE "$results\n\n";
}

close OUTFILE;