Ok so I found out what I was doing wrong, there were two main things that I was doing wrong.
The first thing is that when I got the directory uri with Intent.ACTION_OPEN_DOCUMENT_TREE
I didn't get persistable uri permission, which I now do using Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
and contentResolver.takePersistableUriPermission(uri, takeFlags)
the other part that I was doing wrong was the method of getting the outputStream as I needed to use a contentResolver for it
val out = contentResolver.openOutputStream(newFile.uri)
with these changes everything works as I intended!