SD Card fails to write every capture of IMU sensors

Sketch uses 50416 bytes (19%) of program storage space. Maximum is 253952 bytes.
Global variables use 5883 bytes (71%) of dynamic memory, leaving 2309 bytes for local variables. Maximum is 8192 bytes.

void PrintLine2File(String Line, File dataFile){
        if (dataFile) {
                dataFile.println(Line);
        }
}
void ReadLineOfData(String LineStartText, File dataFile, unsigned long refTime)
{

        String FinalTxtLine = LineStartText;
        FinalTxtLine += "  ~Take";
        FinalTxtLine += String(TakeNumber, DEC);
        FinalTxtLine += "~ ";

        FinalTxtLine += "  ~Time";
        FinalTxtLine += String(refTime, DEC);
        FinalTxtLine += "~  ";
        if(chestPresent)
        {
                if (QuatMode) {
                        // Quaternion data
                        if (chest.dmpGetCurrentFIFOPacket(fifoBuffer)) { // Get the Latest packet
                                // display quaternion values in easy matrix form: w x y z
                                chest.dmpGetQuaternion(&quat, fifoBuffer);
                        }
                        FinalTxtLine += printQuatMPU(quat,NAMECHEST);
                        memset(fifoBuffer, 0, sizeof(fifoBuffer));

                }else
                {
                        //imu::Vector<3> euler = chest.getVector(Adafruit_BNO055::VECTOR_EULER);//comment this
                        //FinalTxtLine += printEuler(euler,NAMECHEST); //comment this
                }
                FinalTxtLine += "  ";
        }
        if(rightHandPresent)
        {
                if (QuatMode) {
                        // Quaternion data
                        if (rightHand.dmpGetCurrentFIFOPacket(fifoBuffer)) { // Get the Latest packet
                                // display quaternion values in easy matrix form: w x y z
                                rightHand.dmpGetQuaternion(&quat, fifoBuffer);
                        }
                        FinalTxtLine += printQuatMPU(quat,NAMEHAND_R);
                        memset(fifoBuffer, 0, sizeof(fifoBuffer));

                }else
                {
                        //imu::Vector<3> euler = rightHand.getVector(Adafruit_BNO055::VECTOR_EULER);//comment this
                        //FinalTxtLine += printEuler(euler,NAMErightHand); //comment this
                }
                FinalTxtLine += "  ";
        }
        if(rightBicepPresent)
        {
                if (QuatMode) {
                        // Quaternion data
                        if (rightBicep.dmpGetCurrentFIFOPacket(fifoBuffer)) { // Get the Latest packet
                                // display quaternion values in easy matrix form: w x y z
                                rightBicep.dmpGetQuaternion(&quat, fifoBuffer);
                        }
                        FinalTxtLine += printQuatMPU(quat,NAMEBICEP_R);
                        memset(fifoBuffer, 0, sizeof(fifoBuffer));

                }else
                {
                        //imu::Vector<3> euler = rightBicep.getVector(Adafruit_BNO055::VECTOR_EULER);//comment this
                        //FinalTxtLine += printEuler(euler,NAMErightBicep); //comment this
                }
                FinalTxtLine += "  ";
        }

        if(rightForeArmPresent)
        {
                if (QuatMode) {
                        // Quaternion data
                        imu::Quaternion quatrightForeArm = rightForeArm.getQuat();
                        FinalTxtLine += printQuat(quatrightForeArm,NAMEFOREARM_R);
                }else
                {
                        imu::Vector<3> euler = rightForeArm.getVector(Adafruit_BNO055::VECTOR_EULER);
                        // Display the floating point data
                        FinalTxtLine += printEuler(euler,NAMEFOREARM_R);
                }
                FinalTxtLine += "  ";
        }

        if(leftForeArmPresent)
        {
                if (QuatMode) {
                        // Quaternion data
                        imu::Quaternion quatleftForeArm = leftForeArm.getQuat();
                        FinalTxtLine += printQuat(quatleftForeArm,NAMEFOREARM_L);
                }else
                {
                        imu::Vector<3> euler = leftForeArm.getVector(Adafruit_BNO055::VECTOR_EULER);
                        // Display the floating point data
                        FinalTxtLine += printEuler(euler,NAMEFOREARM_L);
                }
                FinalTxtLine += "  ";
        }
        if(leftBicepPresent)
        {
                if (QuatMode) {
                        // Quaternion data
                        if (leftBicep.dmpGetCurrentFIFOPacket(fifoBuffer)) { // Get the Latest packet
                                // display quaternion values in easy matrix form: w x y z
                                leftBicep.dmpGetQuaternion(&quat, fifoBuffer);
                        }
                        FinalTxtLine += printQuatMPU(quat,NAMEBICEP_L);
                        memset(fifoBuffer, 0, sizeof(fifoBuffer));

                }else
                {
                        //imu::Vector<3> euler = leftBicep.getVector(Adafruit_BNO055::VECTOR_EULER);//comment this
                        //FinalTxtLine += printEuler(euler,NAMEleftBicep); //comment this
                }
                FinalTxtLine += "  ";
        }
        if(leftHandPresent)
        {
                if (QuatMode) {
                        // Quaternion data
                        if (leftHand.dmpGetCurrentFIFOPacket(fifoBuffer)) { // Get the Latest packet
                                // display quaternion values in easy matrix form: w x y z
                                leftHand.dmpGetQuaternion(&quat, fifoBuffer);
                        }
                        FinalTxtLine += printQuatMPU(quat,NAMEHAND_L);
                        memset(fifoBuffer, 0, sizeof(fifoBuffer));

                }else
                {
                        //imu::Vector<3> euler = leftHand.getVector(Adafruit_BNO055::VECTOR_EULER);//comment this
                        //FinalTxtLine += printEuler(euler,NAMEleftHand); //comment this
                }
                FinalTxtLine += "  ";
        }
        if(headPresent)
        {
                if (QuatMode) {
                        // Quaternion data
                        if (head.dmpGetCurrentFIFOPacket(fifoBuffer)) { // Get the Latest packet
                                // display quaternion values in easy matrix form: w x y z
                                head.dmpGetQuaternion(&quat, fifoBuffer);
                        }
                        FinalTxtLine += printQuatMPU(quat,NAMEHEAD);
                        memset(fifoBuffer, 0, sizeof(fifoBuffer));

                }else
                {
                        //imu::Vector<3> euler = head.getVector(Adafruit_BNO055::VECTOR_EULER);//comment this
                        //FinalTxtLine += printEuler(euler,NAMEhead); //comment this
                }
                FinalTxtLine += "  ";
        }
        if(waistPresent)
        {
                if (QuatMode) {
                        // Quaternion data
                        if (waist.dmpGetCurrentFIFOPacket(fifoBuffer)) { // Get the Latest packet
                                // display quaternion values in easy matrix form: w x y z
                                waist.dmpGetQuaternion(&quat, fifoBuffer);
                        }
                        FinalTxtLine += printQuatMPU(quat,NAMEWAIST);
                        memset(fifoBuffer, 0, sizeof(fifoBuffer));

                }else
                {
                        //imu::Vector<3> euler = waist.getVector(Adafruit_BNO055::VECTOR_EULER);//comment this
                        //FinalTxtLine += printEuler(euler,NAMEwaist); //comment this
                }
                FinalTxtLine += "  ";
        }
        if(leftThighPresent)
        {
                if (QuatMode) {
                        // Quaternion data
                        imu::Quaternion quatleftThigh = leftThigh.getQuat();
                        FinalTxtLine += printQuat(quatleftThigh,NAMETHIGH_L);
                }else
                {
                        imu::Vector<3> euler = leftThigh.getVector(Adafruit_BNO055::VECTOR_EULER);
                        // Display the floating point data
                        FinalTxtLine += printEuler(euler,NAMETHIGH_L);
                }
                FinalTxtLine += "  ";
        }
        if(leftKneePresent)
        {
                if (QuatMode) {
                        // Quaternion data
                        if (leftKnee.dmpGetCurrentFIFOPacket(fifoBuffer)) { // Get the Latest packet
                                // display quaternion values in easy matrix form: w x y z
                                leftKnee.dmpGetQuaternion(&quat, fifoBuffer);
                        }
                        FinalTxtLine += printQuatMPU(quat,NAMEKNEE_L);
                        memset(fifoBuffer, 0, sizeof(fifoBuffer));

                }else
                {
                        //imu::Vector<3> euler = leftKnee.getVector(Adafruit_BNO055::VECTOR_EULER);//comment this
                        //FinalTxtLine += printEuler(euler,NAMEleftKnee); //comment this
                }
                FinalTxtLine += "  ";
        }
        if(leftFootPresent)
        {
                if (QuatMode) {
                        // Quaternion data
                        if (leftFoot.dmpGetCurrentFIFOPacket(fifoBuffer)) { // Get the Latest packet
                                // display quaternion values in easy matrix form: w x y z
                                leftFoot.dmpGetQuaternion(&quat, fifoBuffer);
                        }
                        FinalTxtLine += printQuatMPU(quat,NAMEFOOT_L);
                        memset(fifoBuffer, 0, sizeof(fifoBuffer));

                }else
                {
                        //imu::Vector<3> euler = leftFoot.getVector(Adafruit_BNO055::VECTOR_EULER);//comment this
                        //FinalTxtLine += printEuler(euler,NAMEleftFoot); //comment this
                }
                FinalTxtLine += "  ";
        }
        if(rightThighPresent)
        {
                if (QuatMode) {
                        // Quaternion data
                        imu::Quaternion quatrightThigh = rightThigh.getQuat();
                        FinalTxtLine += printQuat(quatrightThigh,NAMETHIGH_R);
                }else
                {
                        imu::Vector<3> euler = rightThigh.getVector(Adafruit_BNO055::VECTOR_EULER);
                        // Display the floating point data
                        FinalTxtLine += printEuler(euler,NAMETHIGH_R);
                }
                FinalTxtLine += "  ";
        }
        if(rightKneePresent)
        {
                if (QuatMode) {
                        // Quaternion data
                        if (rightKnee.dmpGetCurrentFIFOPacket(fifoBuffer)) { // Get the Latest packet
                                // display quaternion values in easy matrix form: w x y z
                                rightKnee.dmpGetQuaternion(&quat, fifoBuffer);
                        }
                        FinalTxtLine += printQuatMPU(quat,NAMEKNEE_R);
                        memset(fifoBuffer, 0, sizeof(fifoBuffer));

                }else
                {
                        //imu::Vector<3> euler = rightKnee.getVector(Adafruit_BNO055::VECTOR_EULER);//comment this
                        //FinalTxtLine += printEuler(euler,NAMErightKnee); //comment this
                }
                FinalTxtLine += "  ";
        }
        if(rightFootPresent)
        {
                if (QuatMode) {
                        // Quaternion data
                        if (rightFoot.dmpGetCurrentFIFOPacket(fifoBuffer)) { // Get the Latest packet
                                // display quaternion values in easy matrix form: w x y z
                                rightFoot.dmpGetQuaternion(&quat, fifoBuffer);
                        }
                        FinalTxtLine += printQuatMPU(quat,NAMEFOOT_R);
                        memset(fifoBuffer, 0, sizeof(fifoBuffer));

                }else
                {
                        //imu::Vector<3> euler = rightFoot.getVector(Adafruit_BNO055::VECTOR_EULER);//comment this
                        //FinalTxtLine += printEuler(euler,NAMErightFoot); //comment this
                }
                FinalTxtLine += "  ";
        }
        /* New line for the next sample */
        FinalTxtLine += "PNTEND";
        Serial.println(FinalTxtLine);

        if(dataFile){
          Serial.println("SD Present");
          PrintLine2File(FinalTxtLine, dataFile);
        }

}
if (incomingByte == 114)
        {
                if(IMUsInitialized && IMUsCalibrated) {
                        String filename = DataLoggingName();
                        Serial.println("Creating File:" + filename);
                        //File dataFile = SD.open(filename, FILE_WRITE);
                        File dataFile = SD.open(filename, O_CREAT | O_APPEND | O_WRITE);
                        //Run TPose
                        RunTPose(dataFile);

                        PrintLCDLine1("Recording 2 File");
                        PrintLCDLine2(filename);
                        //Current Start Time in tick counts
                        StartTime = millis();

                        //Printing Start Time..
                        TimeLine = "STARTIME " + GetTime();
                        Serial.println(TimeLine);
                        if(dataFile) {
                                PrintLine2File(TimeLine,dataFile);

                        }

                        //main read loop
                        ButtonPushed = false;


                        if (Serial.available() == 0) {
                                Serial.println("Serial port is 0");
                        }
                        else {
                                Serial.print("Serial port is: ");
                                Serial.println(Serial.available());
                        }

                        if (ButtonPushed == true) {
                                Serial.println("Button is pushed");
                        }
                        else {
                                Serial.println("Button is not pushed");
                        }

                        Serial.println("Entering Main Loop");
                        while(Serial.available() && ButtonPushed == false ) {
                                //setting LED to blining red..
                                Recording();
                                //checking button to see if we stop.
                                ButtonPushed = !digitalRead(buttonPin);

                                CurrentTime = millis() - StartTime;
                                ReadLineOfData("PNTSTART", dataFile, CurrentTime);
                                //PrintLine2File(TimeLine,dataFile);
                                //dataFile.flush(); //maybe flush less frequently
                                delay(CaptureDelay);
                        }
                        
                        Serial.println("Exited Main Loop");
                        PrintLCDLine1("Done:" + filename);
                        PrintLCDLine2("Button 2 Record");
                        if(dataFile) {
                                dataFile.close();
                        }
                        StatusAllBad();
                        delay(1000);
                }else {
                        StatusAllBad();
                        Serial.println("You Must Initialize and Calibrate ALL of the Sensors Prior to Calibration");
                        delay(2000);
                }
                incomingByte = Serial.read();
        }

Your post is lacking critical information

Do yourself a favour and please read How to get the best out of this forum and modify your post accordingly (including code tags for the whole code and necessary documentation for your ask).