misc/m3u: Split m3u metadata write so that newline is infallible
This basically fixes #28641, at least the part where user data is irreversibly lost.
Writing metadata to file may still fail, and it appears there is nothing VLC can do about that, but with this fix, all tracks will still be present in the resulting file, and will not be lost on m3u file read+write.