My Sd is saving same data multiple times

am working with sd card module, rfid and rtc project. it save the time and rfid uid on the sd. but am getting multiple storage on the sd

#include <SPI.h>
#include <MFRC522.h>
#include <SD.h> // for the SD card
#include "RTClib.h" // for the RTC
#include <LiquidCrystal_I2C.h> // for the 12c lcd
#include <Wire.h>
 
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.

// define select pin for SD card module
#define CS_SD 4
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  

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

// Instance of the class for RTC
RTC_DS1307 rtc;


// Pins for LEDs and buzzer
const int redLED = 6;
const int greenLED = 7;
const int buzzer = 5;


 
 String uid;
 String nm;
 String reg;
void setup() 
{

  // Set LEDs and buzzer as outputs
  pinMode(redLED, OUTPUT);  
  pinMode(greenLED, OUTPUT);
  pinMode(buzzer, OUTPUT);
  //LCD Initializations
    lcd.begin(16,2);
  // Init Serial port
  Serial.begin(9600);
  while(!Serial); // for Leonardo/Micro/Zero
  
  Serial.begin(9600);   // Initiate a serial communication
  SPI.begin();      // Initiate  SPI bus
  mfrc522.PCD_Init();   // Initiate MFRC522
   //Setting up device
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Initializing...");
  digitalWrite(greenLED, HIGH);
  digitalWrite(redLED, HIGH);
  tone(buzzer, 3000);
  delay(3000);
  digitalWrite(greenLED, LOW);
  digitalWrite(redLED, LOW);
  noTone(buzzer);
  
    // Setup for the SD card
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("SD Check");
  if(!SD.begin(CS_SD)) {
    Serial.println("initialization failed!");
    lcd.setCursor(0,1);
    lcd.print("SD Not Found");
    return;
  }
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("SD Check");
    lcd.setCursor(0,1);
    lcd.print("SD Found");
    lcdprintmain();

  // Setup for the RTC  
  if(!rtc.begin()) {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("RTC no Found");
    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()) {
        lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("RTC Not Running"); 
   
  }

}
void loop() 
{
  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent()) 
  {
    return;
  }
  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) 
  {
    return;
  }
  //Show UID on serial monitor
  
  String content= "";
  
  byte letter;
  for (byte i = 0; i < mfrc522.uid.size; i++) 
  {
     Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
     Serial.print(mfrc522.uid.uidByte[i], HEX);
     content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
     content.concat(String(mfrc522.uid.uidByte[i], HEX));
      content.toUpperCase();
      uid =content.substring(1);
  }
  boolean authorized = false;
  char *name = "";
  char *regn="";
  content.toUpperCase();
  
  if (content.substring(1) == "A3 FD 39 32") //change here the UID of the card/cards that you want to give access
  {
     authorized = true;
     name = "Atu Evelyn E";
     regn= "13/EEN/013";

  }
     if (content.substring(1)  == "23 4C 5E 25") //change here the UID of the card/cards that you want to give access
 {
   authorized = true;
   name = "Terrence Uninke";
   regn= "13/EEN/118";
  }
    if (content.substring(1)  == "76 D3 C6 1F") //change here the UID of the card/cards that you want to give access
 {
   authorized = true;
   name = "Usang Prince O"; 
   regn= "13/EEN/091";
  }
   if (content.substring(1)  == "A3 BF 8F 32") //change here the UID of the card/cards that you want to give access
 {
   authorized = true;
   name = "Ikongha Victor B"; 
   regn = "13/EEN/053";
  }
  
  if (content.substring(1) == "33 0F BE 25") //change here the UID of the card/cards that you want to give access
 {
   authorized = true;
   name = "Kurukpe O Anderson";
   regn= "13/EEN/086"; 
  }
  nm= name;
  reg=regn;
  if(authorized){
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("valid Voter");
    lcd.setCursor(0,1);
     lcd.print(name); 
 // Sound the buzzer/greenLed on when a card is read
  tone(buzzer, 1000);
  digitalWrite(greenLED,HIGH); 
  delay(100);        
  noTone(buzzer);
  digitalWrite(greenLED,LOW);
    delay(3000);
     lcdprintmain();
  }
 
 else   {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Invalid Voter");
    lcd.setCursor(0,1);
    lcd.print(uid);
    tone(buzzer, 3000);
    digitalWrite(redLED,HIGH); 
    delay(1000);        
    noTone(buzzer);
    digitalWrite(redLED,LOW);
    delay(3000);
    lcdprintmain();

  }

   digitalWrite(CS_SD,LOW);
  
  // Open file
  myFile=SD.open("DATA.txt", FILE_WRITE);

  // If the file opened ok, write to it
  if (myFile) {
    Serial.println("File opened ok");
    myFile.print(uid); 
    myFile.print(", ");
    myFile.print(nm);   
    myFile.print(", ");
      myFile.print(reg);   
    myFile.print(", ");
    // Save time on SD card
    DateTime now = rtc.now();
    myFile.print(now.year(), DEC);
    myFile.print('/');
    myFile.print(now.month(), DEC);
    myFile.print('/');
    myFile.print(now.day(), DEC);
    myFile.print(',');
    myFile.print(now.hour(), DEC);
    myFile.print(':');
    myFile.println(now.minute(), DEC);
    myFile.close();
 
    
  }
  else {
    Serial.println("error opening data.txt");  
  }
  // Disables SD card chip select pin  
  digitalWrite(CS_SD,HIGH);
  
}

void lcdprintmain(){
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.write("Voting System");
  lcd.setCursor(0,1);
  lcd.write("Swipe Your Card");
}