I can't tell specifically from your post what the issue is, but here are possibilities to explore:
Is there content there that is not looking like proper PDF format?
Is there no content there, for instance file-length-0?
Is there a folder-protection issue preventing you from either writing or reading back the content?
To help explore these, you may want to try variations, such as vary your folder, or vary the content, or vary between using your custom code and out-of-box code, to see if it makes a difference that offers a clue.