When you re-connect & re-join the channel the names list is sent, so when you get raw 366 (End of Names list) simply loop through $nick($2,N) and use /write's -s switch.
raw 366:& #channelname *:{
var %i = 1
while ($nick($2,%i)) {
write -s $+ $v1 file.txt $v1
inc %i
}
}
Change:
#channelname to your channels name.