You should always return the second output of fopen and check the f_id value:
[f_id,msg] = fopen(txt_name,'wt');
assert(f_id>=3,msg)
The cause is, as Bob Nbob already wrote, likely to be that the file could not be found/created. Typically this occurs if the path name is not correct, or you do not have write permission for that location. You will have to check the path name using exist, check your user permissions, etc.
Best Answer