It seems that saving files with long names leads to problems for some reason. I won't write code here since it is hard to reproduce, but below is an image that shows this issue.
Folder structure definitely exists, you can see that for some filenames it works just fine. But then for other names without any weird special characters it fails.
I have tried other variants like giving absolute path, but still it seems to fail. Is there maybe a fix to this, other than saving a file with a timestamp perhaps or some other kind of unique random naming?
EDIT
For more clarification, folder structure is the same for each of the 5 examples (everything up to the last \), I have only changed filename and for 3 examples it works fine but for other 2 it doesn't.