I had a situation recently where I could not write the $_POST array to a file. During debug, I learned that the $_POST data was being saved to a variable correctly, and I could output that variable to the screen, send it back as my HTTP response payload, and even write literally anything else to the file. But the $_POST array simply would not write to a local file.
I did all my Linuxey t-shooting: checked selinux, checked PHP permissions, checked out-of-band things like inodes and disk space, but no go.
So I changed my method to this, which worked. No clue why. Your milage may vary...
file_put_contents(, file_get_contents( ));