store an array of all the terms existing

Not sure what the problem is, you’re practically there! You can use your code anywhere (as long as it’s after the init hook), not just in template files.

$terms = get_terms( 'MYTAXONOMY' );
$term_slugs = wp_list_pluck( $terms, 'slug' );

wp_list_pluck() is a very cool little function that will pluck a field out of an array of arrays/objects & return it as a single array:

print_r( $term_slugs ); // Array( 'slug_1', 'slug_2', ... )