can't write data in SD card

I have a code for logging date, time and sensor value to SD card. A text file is created in the SD card. But after that, I am unable to update the data in the SD card. I am using the RTC module, SD card module and LoRa with Arduino nano. Code is shown below.

Please help me.

#include <RHReliableDatagram.h>
#include <RH_RF95.h>
#include “RTClib.h”
#include <SPI.h>
#include <SD.h>

RTC_DS1307 rtc;
File myFile;

#define node_address 12
uint8_t gateway_address = 11;
const int sensor_pin = A1;
float level;

/* Chip selection */
const int CS1 = 8;/SD Card/
const int CS2 = 10;/LoRa/

/* Configure LoRa driver */
RH_RF95 driver(10,2);
RHReliableDatagram manager(driver,node_address);

void setup () {
pinMode(sensor_pin, INPUT);
pinMode(CS1,OUTPUT);
pinMode(CS2,OUTPUT);

/--------Serial port connection setup--------/
Serial.begin(9600);

/----------RTC Initialization----------/
Serial.println(F(“Initializing RTC…!”));
if (! rtc.begin()) {
Serial.println(F(“Couldn’t find RTC”));
}
if (! rtc.isrunning()) {
Serial.println(F(“RTC is NOT running!”));
// rtc.adjust(DateTime(2019, 11, 12, 12, 32, 0)); // (Year,Month,Date,Hour,Min,Sec)
}

/----------SD CARD Initialization----------/
digitalWrite(CS2,HIGH);
delay(500);
digitalWrite(CS1,LOW);
Serial.println(F(“Initializing SD card…”));
if (!SD.begin(CS1)) {
Serial.println(F(“initialization of SD Card is failed!”));
return;
}
Serial.println(F(“Initialization of SD Card is done.”));
/----------LoRa Initialization----------/
digitalWrite(CS1,HIGH);
delay(500);
digitalWrite(CS2,LOW);
if (manager.init())
{
Serial.println(F("LoRa Successfully Initialised "));
} else {
Serial.println(F(“LoRa initialization failed”));
}
driver.setFrequency(433.0);
driver.setTxPower(14,false);
Serial.println();
}

void loop () {
DateTime now = rtc.now();
/----------Date----------/
Serial.print(now.year(), DEC);
Serial.print(’/’);
Serial.print(now.month(), DEC);
Serial.print(’/’);
Serial.print(now.day(), DEC);
Serial.print(’,’);
/----------Time----------/
Serial.print(now.hour(), DEC);
Serial.print(’:’);
Serial.print(now.minute(), DEC);
Serial.print(’:’);
Serial.print(now.second(), DEC);
Serial.println();

/----------SD card----------/
digitalWrite(CS2,HIGH);
delay(500);
digitalWrite(CS1,LOW);
myFile = SD.open(“test.txt”, FILE_WRITE);
if (myFile){
/----------Saving Date----------/
myFile.print(now.year(), DEC);
myFile.print(’/’);
myFile.print(now.month(), DEC);
myFile.print(’/’);
myFile.print(now.day(), DEC);
myFile.print(’,’);
/----------Saving Time----------/
myFile.print(now.hour(), DEC);
myFile.print(’:’);
myFile.print(now.minute(), DEC);
myFile.print(’:’);
myFile.print(now.second(), DEC);
myFile.println(’,’);
level = analogRead(sensor_pin);
myFile.print(level);
myFile.println();
myFile.close();
} else {
Serial.println(“Error opening test.txt”);
}
digitalWrite(CS1,HIGH);
delay(500);
digitalWrite(CS2,LOW);
char data[RH_RF95_MAX_MESSAGE_LEN];
sprintf(data,"$%d#%d",node_address,level);
Serial.print("Level transferred is ");
Serial.println(data);
if(!manager.sendtoWait((uint8_t*)data,sizeof(data),gateway_address))
{
Serial.println(“Gateway offline”);
}
delay(500);
}