"public://" is not resolved correctly to the full path
The reason there's no $base_url is because the script you're running isn't in a HTTP context; when Drupal bootstraps, unless you've specified a $base_url in settings.php, it retrieves this value from $_SERVER['HTTP_HOST'] which doesn't exist in the command line context.

To remedy this, you can set the $base_url in your settings.php or, if you're running Drush, use the --uri argument.

drush scr --uri="http://www.example.com" my_script.php