avoid duplicated records with drupal_write_record
This function can take 3 arguments , in this situation the third argument acts as an array of primary keys and if we pass the third argument to the function (primary key), it will update the record, if don't pass - it will insert a new record .