how to refine output of stored temprature and humidaty (refine the deviated bord

hello all
a program to store temperature and humidity from DHT22 sensor in SD card
the snapshot of results attached
please i need your to refine the results(output) so that all border line be straight(red arrow refer to the deviated line)
**second why the heading is duplicated **

#include <SPI.h> //for the SD card module
#include <SD.h> // for the SD card
#include <DHT.h> // for the DHT sensor
#include <RTClib.h> // for the RTC

//define DHT pin
#define DHTPIN 8     // what pin we're connected to

// uncomment whatever type you're using
//#define DHTTYPE DHT11   // DHT 11 
#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// initialize DHT sensor for normal 16mhz Arduino
DHT dht(DHTPIN, DHTTYPE);

// change this to match your SD shield or module;
// Arduino Ethernet shield and modules: pin 4
// Data loggin SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
const int chipSelect = 10; 

// Create a file to store the data
File datalog;

// RTC
RTC_DS1307 rtc;

void setup() {
  //initializing the DHT sensor
  dht.begin();

  //initializing Serial monitor
  Serial.begin(9600);
  
  // setup for the RTC
  while(!Serial); // for Leonardo/Micro/Zero
    if(! rtc.begin()) {
      Serial.println("Couldn't find RTC");
      while (1);
    }
    else {
      // following line sets the RTC to the date & time this sketch was compiled
      rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    }
    if(! rtc.isrunning()) {
      Serial.println("RTC is NOT running!");
    }
    
  // setup for the SD card
  Serial.print("Initializing SD card...");

  if(!SD.begin(chipSelect)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
    
  //open file
 datalog=SD.open("DATA.txt", FILE_WRITE);

  // if the file opened ok, write to it:
  if (datalog) {
    Serial.println("File opened ok");
    // print the headings for our data
    datalog.println("   DATE    |   TIME    | TEMPERATURE| HUMIDITY");
  }
  datalog.close();
}

void loggingTime() {
  DateTime now = rtc.now();
  datalog = SD.open("DATA.txt", FILE_WRITE);
  if (datalog) {
    datalog.print(now.year(), DEC);
    datalog.print('/');
    datalog.print(now.month(), DEC);
    datalog.print('/');
    datalog.print(now.day(), DEC);
    datalog.print("  |  ");
    datalog.print(now.hour(), DEC);
    datalog.print(':');
    datalog.print(now.minute(), DEC);
    datalog.print(':');
    datalog.print(now.second(), DEC);
    datalog.print(" |   ");
   
  }
  Serial.print(now.year(), DEC);
  Serial.print('/');
  Serial.print(now.month(), DEC);
  Serial.print('/');
  Serial.print(now.day(), DEC);
  Serial.print("|   ");
  Serial.print(now.hour(), DEC);
  Serial.print(':');
  Serial.print(now.minute(), DEC);
  Serial.print(':');
  Serial.print(now.second(), DEC);
  Serial.print("  |    ");
  
  datalog.close();
  delay(1000);  
}

void loggingTemperature() {
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  // Read temperature as Celsius
  float t = dht.readTemperature();
  float h=dht.readHumidity();
  // Read temperature as Fahrenheit
  //float f = dht.readTemperature(true);
  
  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) ) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  
  //debugging purposes
  Serial.print("Temperature: "); 
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print("|   ");
  Serial.print("Humidity: "); 
  Serial.print(h);
  Serial.println(" %");
  //Serial.print(f);
  //Serial.println(" *F\t"); 
  
  datalog = SD.open("DATA.txt", FILE_WRITE);
  if (datalog) {
    Serial.println("open with success");
    datalog.print(t);
    datalog.print("°C   | ");
   datalog.println(h);
   
  }
 datalog.close();
}

void loop() {
  loggingTime();
  loggingTemperature();
  delay(9000);
}

Use tabs

Serial.print("\t|");

to position the dividers rather than spaces

saif221984:
why the heading is duplicated

Although it's not the normal or intended behavior. There seems to be some conditions where, when you upload a sketch, the Arduino IDE will reset the Arduino board at the start of the compilation, which causes the sketch to run for a few seconds while it compiles, then the upload occurs and the sketch starts over again. That would match with your results. What you could do to avoid the duplicate header is to use SD.exists():
https://www.arduino.cc/en/Reference/SDexists
to check if the file exists already and, if so, don't write the heading to the file.

The Arduino will reset when the Serial monitor is opened by which time the heading, and potentially a number of readings, will have been written.

Another way to straighten your borders is to make sure that all of your dates and times are the same length by inserting leading spaces or zeroes. For example:

    datalog.print('/');
    if (now.month() < 10)
      datalog.print('0');
    datalog.print(now.month(), DEC);
    datalog.print('/');
    if (now.day() < 10)
      datalog.print('0');
    datalog.print(now.day(), DEC);
    datalog.print("  |  ");
    if (now.hour() < 10)
      datalog.print(' ');
    datalog.print(now.hour(), DEC);
    datalog.print(':');
    if (now.minute() < 10)
      datalog.print('0');
    datalog.print(now.minute(), DEC);
    datalog.print(':');
    if (now.second() < 10)
      datalog.print('0');
    datalog.print(now.second(), DEC);
    datalog.print(" |   ");

thank u very much i will try it