Simply due to the fact, or at least in my experience, # or $chan returns $null when referenced in a script that uses the ON NICK event.