$handle = fopen($filename, 'w') or die('Cannot open file: '.$filename);The code below adds new line to the existing content:
$handle = fopen($filename, 'a') or die('Cannot open file: '.$filename);So, the difference is in fopen($filename, 'w') and fopen($filename, 'a')