CSV logging, the parameters don't log on the last column

Hi everyone, I’m experiencing a issue while logging data from some sensors, when I create the file I determinate that it will store 3 columns, but while the program is running it stores correctly the first 2 columns but the third one is write bellow the 2 column on the line below, then on the other measure it’ll store correctly the column 1 and and column2 right to each other, but it creates again another line just to put what’s suppose to be in the third column (alongside the others) on the 2 column.

can you help me?

the code:

#include <SPI.h>
#include <SD.h>

File myFile;
#define SD_CS 4

void setup() {
  // put your setup code here, to run once:
Serial.print("Initializing SD card...");

  if (!SD.begin(SD_CS)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("TempH.csv", FILE_WRITE);


    // if the file opened okay, write to it:
  if (myFile) {
    //Serial.print("Writing to fa.txt...");
    myFile.println("Temperatura; distancia; chuva");
    // close the file:
    myFile.close();
    //Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}
}

void loop() {
  nsigned long currentTime=millis();

if (currentTime-previousTime>=interval){

 // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("TempH.csv", FILE_WRITE);
  
 // if the file opened okay, write to it:
  if (myFile) {
    //Serial.print("Writing to fa.txt...");
    myFile.print(temperature);
    myFile.print(";");
    myFile.println(d);
    myFile.print(";");
    myFile.println(val_a);
    
    // close the file:
    myFile.close();
    
    //Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("SD error");
  }

  previousTime=currentTime;

}

its an example of what happens on the .csv file:

Temperatura distancia chuva
16,8 32
680
16,5 33
680

Thanks in advance

Should

    myFile.println(d);

be

    myFile.print(d);

?

@dannable thanks a lot for your support, it was crucial!

earlier in the afternoon, i found that i had to print ";" for each column(for the third column 2;, for the forth 3; and so on), but it remained to keep other and other line. With your help I was able to test a few more setups and then i found that the one that work is:

   myFile.print(temperature);
      myFile.print(";");
      myFile.print(d);
      myFile.print(";");
      myFile.print(val_a);
      myFile.print(";");
      myFile.print(hora);
      myFile.print(";");
      myFile.println(data);

the last one needs to be a println to provide another line, for another loop

Cheers!