How to save text File privately which should be stored in device storage

safe means will not get deleted?
yes, just use Legacy and the file will be stored in shared storage accessible for all apps
next time if you reinstall the app and want to read the file again, you will need SAF, see also Some basics on Android storage system

Taifun