Here's a basic example. Look up "/help raw events" and feel free to ask if you don't get the principle. smile
Code:
; custom alias "/writenames #channel"
alias writenames {
  ; request names list
  names $$1
  ; global variable storing the name of the channel
  set -en %writenames $1
}

; names reply
raw 353:*: { 
  ; reply is for the channel in question
  if ($3 == %writenames) {
    ; write names to file
    write names $+ $v1 $+ .txt $4-
    ; halt default display
    haltdef
  }
}

; 'end of names' reply
raw 366:*: { 
  ; reply is for the channel in question
  if ($2 == %writenames) {
    unset %writenames
    haltdef
  }
}