Your variable is out of scope for functions on functions.php. The easiest thing to do is declare it global on both the external page and in the function on functions.php using it.
FYI, what you are doing is generally considered very sloppy coding for the WP environment. It's OK if this is for your own site which you maintain, but virtually unusable if you may want others to use your code. Relative references to required WP core files is considered unacceptable. For external code to use WP resources the page either needs to be a page template or requests need to be sent through admin-ajax.php or admin-post.php.
It's also not a good idea to directly edit a theme's functions.php file, your custom code should reside in a child theme or plugin and interface with WP through filters and actions. You may very well be doing this, but it's worth mentioning in case you are not.
You don't have to do any of this, it's your site. But if you think you might like to share your efforts with the WP community, or you simply take pride in well written code, it's best to follow community established practices.