Seems like reading the file, adding the lines, uniqing the array then writing it back out would be simpler. Am I missing something?