Drush isn't bootstrapping drush script
Drush shell scripts such as the one you show above do not automatically bootstrap to any argument passed to them.  (EDIT: This is due to a bug.)  You have a few options.

1: Force the bootstrap:

$site = drush_shift();
drush_bootstrap_max_to_sitealias($site);
drush_invoke('core-status');


2: Do all of your work in a subshell:

$values = drush_invoke_process($site, 'core-status');

Those two should get you started.  Note that option number two will re-bootstrap Drupal in an isolated subshell every time you call drush_invoke_process.  drush_invoke always works on the currently-bootstrapped site, and you can only bootstrap once.  Therefore, that drush_invoke('use', ...) trick won't work.  'use' is only for use in the shell, not in scripts.

There's another error above.  This code isn't working as you expect it is:

$result=drush_invoke('core-status');
drush_print($result['output']);


What's really happening here is that drush_invoke is printing the output of drush status to stdout, and drush_print is printing nothing.  You'll get $result['output'] if you use drush_invoke_process.

In my somewhat biased opinion, the Drush chapter of the Definitive Guide To Drupal 7 covers these topics pretty well.  It is available for download as a free sample chapter at http://definitivedrupal.org/book/26-drush