@gr33nduino, please edit your opening post, select all code and click the </> button to apply so-called code tags and next save your post. It makes it easier to read, easier to copy and prevents the forum software from incorrect interpretation of the code.
The above might be the cause of your problem; you do the same in loop() as well. You open a file, if it fails you still try to write to it and you close it. Closing a file (file handle) that is not open can result in crashes.