How do I pass a PHP variable to Drupal.settings global javascript?
calling drupal_add_js in hook_init is a fairly standard response to this kind of question, as is hook_boot.

hook_init is used for setting up things required by the page - but doesnt run on cached pages.

hook boot is used for code that has to run on cached pages as well as uncached pages.

The way I usually debug this kind of thing is with the javascript console. In chrome, open the console and type 

Drupal.settings


hit enter and it should print out the whole settings object for you to inspect. This will let you see what you have. 

I suspect the problem may be down to when hook_page_build gets fired on admin pages if Im reading your question correctly. 

Uncaught TypeError: Cannot read property 'my_var' of undefined 


means that 

Drupal.settings.MY_MODULE


evaluates to undefined. It could be at any level. 
so try the javascript console trick and see what you find (is Drupal there.. is drupal.settings there). 

you could also try

(function ($) {
    Drupal.behaviors.MY_MODULE = {
    attach: function(context,settings) {
    alert("test");
    alert(settings.MY_MODULE.my_var);
   }   
  }
})(jQuery);


which is more keeping with how it is documented for behaviours on drupal.org