It turned out that the permission for the dynamics folder was 755, it needed to be 775. After that the 2nd method worked just fine! Thanks for all the help and improvement suggestions! As far as using ">" to open instead of "+>", the page will be changed in some way almost every time this script is called so the whole page has to be re-written.
So '>' is almost certainly what you want rather than '+>' which opens the file for read/write, given that your script doesn't read from the file. From the open documentation:
You can put a '+' in front of the '>' or '<' to indicate that you want both read and write access to the file