I’ve found the solution here https://github.com/godotengine/godot/issues/66014#issuecomment-1501894950
The issue is that my .tres files get the extension .remap added to them.
This is the code that solved the issue:
if file_name.ends_with(".remap"):
file_name = file_name.trim_suffix(".remap")