well, for one thing ON NICK will only work if you're online and see it. however, there's a few ways this can be done:
on *:notify: {
if (($nick == name) && ($nick != $me)) { /msg nickserv ghost $nick password }
}
That will work if the nickname is in your notify list (/notify nickname) and your nicklist is turned on (/notify on) when you connect to the network.