Got three small things to note:
It is quite inefficient to loop with $lines in the while condition. That's because the $lines identifier is an identifier that has to do quite some processing before it can return the result.
1. It must open the file.
2. Check how many lines there are.
3. Close the file.
4. Return the result.
That means, with each iteration, you open/close the file.
You can avoid all that by putting $lines() in a variable and comparing to that, since the value is already stored in memory (it's a value assigned to a local variable), it does not need to open/close the file.
You can use set -u %var if you want the variable to auto-unset itsself when the script finishes, thus making the unset command obsolete. Or better yet, use a local variable, which destroys itsself automatically when the script finishes.
Lastly, this is a detail, but in the invite command, you could have used $ifmatch or $v1.
I would have used /filter with -k flag, thus taking advantage of the internal loop (fast), and with a minimal amount of code. Then again, that only works from mIRC 6.15 and on. In those cases, the file handling commands are a great alternative.
These are just tips, not trying to be offensive or anything
Greets