How to pass a PHP $_GET variable and fetch/output it?

get_query_var() only works with the Core WP_Query object:

Retrieve public query variable in the WP_Query class of the global
$wp_query
object.

https://codex.wordpress.org/Function_Reference/get_query_var

Your mistake is a simple PHP one: The key is foo, not bar.

$foo = $_GET['foo'];
echo $foo;

But please do not echo user supplied data to the page without sanitizing it.

error code: 523