Problem with fwrite () - Generates duplicate rows in the file

Hello,
I have a problem with this code:


$r1 = "1;2;3";
$r2 = "4;5;6";
$r3 = "7;8;9";

$r = $r1 . PHP_EOL . $r2 . PHP_EOL . $r3 . PHP_EOL;

$nomeFile = 'test.csv';
$file = fopen($nomeFile, 'a') or die ('Error' . $nomeFile);
fwrite($file, $r) or die ('Error' . $nomeFile);
fclose($file);

Using Safari browser on Mac OS X, when I load the page, in the file created rows are duplicated.
If you reload the page without closing the browser tab the script works well, adding three lines to the file.

Where am I wrong?

Taken from http://www.php.net/manual/en/function.fopen.php:

‘a’ Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it.

You probably want w+

No, I want append data to end of file.

It’s as if the browser loads the page 2 times.