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

Please explain exactly what you mean by 'cancel'

With 'cancel the file' I mean "SD.remove("valori.txt");"