SD.mkdir() just create a file, if insert SD card before turn on the board

In setup(), SD.mkdir("SENSOR") will create the dir on root and current path will become that one (SENSOR). If the same dir already exists, it will just become current. Further there is no need to explicitly set path for the filename, otherwise it will actually try to write in "SENSOR/filename.CVS", the full path with filename becomes "/SENSOR/SENSOR/filename.CVS". Certainly '/SENSOR/SENSOR' dir doesn't exists, if lib itself even can parse such long string...

Just use filename instead, since current path is already set:

  char str[32] = "";
  //strcat(str, DATA_DIR);
  //strcat(str, "/");
  strcat(str, "20191213");
  strcat(str, RECORD_FILE_EXT);

When use SD lib, I'm usually doing something as follows:

bool SDExists; 

void setup() {
  SDExists = SD.begin(10);   
  ...
}

void loop() {
  if (SDExists) 
  {
     //do something on SD card
  }
}

Since there is no SD.end() method for the SD lib, card must be inserted before firmware start to execute and must not be ejected until power is turned off.

Ans since many SD card modules do not have pin which can indicate to MCU that SD card is physically inserted or ejected, inside loop() any operation with SD card must fail if it is physically ejected after setup() and non of further actions should be possible with SD card.

I have made altered SD lib with SD.end() method which correctly flush existed data, release instance of the class, thus it will be able to eject and switch SD cards whenever explicitly ordered by firmware itself.