Well, you can put it into the same event. Plus there is no need to check if it exists first, you're going to clear and write to it anyway wink
No need for the -s switch either, now that its cleared.
Code:
raw 366:& #channelname *:{
  write -c file.txt
  var %i = 1
  while ($nick($2,%i)) {
    write file.txt $v1
    inc %i
  }
}