You can always use a not-so-well-known feature of mirc to solve the problem. Try the following:

alias cd {
;Your code goes here
}

Now, instead of using $cd in your code, try using $.cd or$/cd. Using the identifiers in this way lets mirc know that you want a result returned from your own code vesus mIRC's internal code.