There are a lot of subtle security holes in what you're doing. You really should (re)consider using chanserv, it's almost always the best choice.
Are you using strict and using warnings? If not, that should be your first step. As suggested above, you should check the value of $conn->{channel} and $nick before proceeding, and at least add a generic handler for unhandled events, maybe to redirect them to stderr, if you don't already have one.
If you post more code this will be a lot easier to troubleshoot, at least the whole on_join subroutine.