I'm trying to append data in file   

I have an array result contains this value :

```
Array ( [0] => Array ( [name] => Fanny [asset] => 1034 ) ) Array ( [0] => Array ( [name] => Gabriel [asset] => 1089 ) ) Array ( [0] => Array ( [name] => Martin [asset_no] => 1520> ) ) 

```

I use a foreach to get the values and then insert them in a file :

```
foreach ($result as $value){
  $name = $value['name'];
  $asset = $value['asset'];
  $dir = "C:/Users/<users>/data";
  if (!is_dir($dir)) {
    mkdir($dir,0777);
  }
file_put_contents("$dir/data", "$name , $data \r", FILE_APPEND);

```

The data in my data file is :

```
Fanny, 1034
Gabriel, 1089
Martin, 1520

```

When I rerun my file it duplicates the values in the file that stores my data:

```
Fanny, 1034
Gabriel, 1089
Martin, 1520
Fanny, 1034
Gabriel, 1089
Martin, 1520

```

I would like to prevent duplication for existing values   

Can anyone tell me where the error. Thank you for your help !