This one doesn't work with Companion and the compiled APK on Android 11+ as it doesn't delete the text file when Companion or the APK is closed. Therefore, after testing with Companion, the file cannot be overwritten via the APK and vice versa.
So either you
do not test with Companion or
delete the file via Companion before closing Companion or
the file name must be different with Companion and APK.
Note: If the user uninstalls and reinstalls the app it does not work anymore, because the reinstalled app is then a new app and cannot overwrite the existing test file. The only way to avoid this is to check if the test file already exists and if so, give it a new name or you must use SAF to access it (on Android 11+).
In addition, no storage permissions should be requested for the Shared folders on Android 11+. I have pointed out this bug countless times. However, when using the EFile extension, this is possible on Android 11+ without storage permissions (just as it should be!).