I think he wants the script to ask someone for an invite, not to actually invite someone or to join when invited.
From what I understood, the bot is automatically asking Chanserv for an invite, but then doesn't actually accept the invitation.
Y'know, an even easier method would just to be:
/cs invite #channel
.timer 1 5 join #channel
That basically assumes that Chanserv will give you the invite, and then try joining the channel 5 seconds later. Not the most clean way of doing it, but surely the easiest.