save all ublox neo-6m serial output to SD card module in raw mode

I wrote this code for save all input data from serial (software serial) into a file with SD module

  • FILE1: created by arduino and save it in SD Card
  • FILE2: created with minicom with USB2TTL

And when comparing two files; In most cases, there is no problem

But we see that the file made by Arduino ignores several characters. why? my code have a problem?

I wonder if it has something to do with opening and closing the file for every 100 characters.