Access User Data from external script inside a custom module
The code snippet is bootstrapping Drupal by assuming it's in Drupal's root path (i.e. require_once 'autoload.php';) To have it runnable from the module dir, you'll have to alter the relative path to make it work from wherever your script is at (e.g. is your module is in DRUPAL_ROOT . 'modules/custom/my_module/scripts/my_script.php' you would have use the path ../../../../includes/autoload.php to reach it). 

Depending on what you're doing, you might want to consider a custom Drupal Console/Drush command as a part of your module instead of a PHP script that has to assume/find the location for bootstapping Drupal.