PHP不断向csv文件多次添加数据

Im trying to add data to a csv file, however every time i run the php script it will add the data two or three times and that is of course super annoying! Just wondering if anyone has an idea of why this is happening? PHP Code:

$my_file2 = 'TEMP/temp.csv';
$handle = fopen($my_file2, 'a');
$data = "Mobile,".$mobi.",Message,".$message."
";
fwrite($handle, $data);
fclose($my_file2);

An example of the csv file with double entry: enter image description here

</div>

Have you tried to use fputcsv function?

fputcsv ( resource $handle , array $fields [, string $delimiter = "," [, string $enclosure = '"' [, string $escape_char = "\\" ]]] ) : int