How to get blog_id of an MU site when running a custom function on the parent site

You need to use the global $current_blog instead.

$GLOBALS[‘current_blog’]->blog_id

will return the correct id.