Code:
if (!$read(%file,w,%id)) {
  write %file %id
}


Unordered text files are not efficient, I would suggest using hash tables for this purpose.