SD.begin fails after the mircoSd is written & arduino resetted

You've got some logic to check the file size after you open it, and I don't understand how that affects the subsequent code. Could you show the sequence of messages printed on Serial if you reset the Arduino without first removing the file?