"global" keyword does not work from within drush script
To solve it I had to add global $foo; before declaring $foo.

I suppose it relates to this: http://php.net/manual/en/language.variables.scope.php#98811