I am trying to simple run fopen() in the functions.php, and have also tried it in a test.php wordpress template file.
But it does not w
You need to use the full file path instead of a relative one.
Use the WordPress function get_template_directory()
to get the path to your template directory. From there add the path to your file.
Change:
var_dump(csv_to_array('csv/nationality-codes.csv'));
To:
var_dump( csv_to_array( get_template_directory() . 'csv/nationality-codes.csv' ) );