I am trying to track all ops in my channel to see who has been in the channel. this script I wrote writes all the ops into op.txt but it duplicates the ops within the text. What is wrong with this script?

on *:OP:#Mychan: {
var %i = 0
while (%i <= $lines(op.txt)) {
if ($opnick !isin $read(op.txt,%i)) {
write op.txt $opnick
else { inc %i 1 }

Intelligence: It's better to ask a stupid question, then to prove it by not asking....