Please tell me what's wrong with my following lines of code while I am trying to write in a text file.

PHP Code:

<?php

$file
="list1.txt";
$file_array=file($file);

$handle=fopen("list2.txt","a");

foreach(
$file_array as $line)
{
      
fwrite($handle,$line);
}

fclose($handle);

?>
Thank you so much for help.