Help, ethernet and SD, error ÿ

So the problem happens when the code is here:

while(myFile.available())
          {
            if(parar_erro == 20)
            {
              Serial.println(F("Erro, o cartão retornou está em loop !"));
            delay(4000);
            break;
            parar_erro == 20
            }
           char buffer_arquivo[20];
           int k = 0;
           
           while(k < 20)
           { 
           
             c = myFile.read();
           
           if(c == -1)
           {
            Serial.println(F("Erro, o cartão retornou -1 !"));
           parar_erro ++;
           break;
           
           }
           buffer_arquivo[k] = char(c);
           k++;
           if(k == 20){
             
            for (int i=0; i < 20; i++)
            {
           client.print(buffer_arquivo[i]);
           Serial.print(buffer_arquivo[i]);
           }
         }

But only after i have saved files to the SD in the section, i mean the error occurs only after this code happens:

if(pegar_codigo == 3)// último menu, salva os dados no SD
  {
  lcd.setCursor(0,0);
  lcd.print(F("SALVANDO...                                                "));
  digitalWrite(4,LOW);
  digitalWrite(10,HIGH);
  
  
  
   
   myFile = SD.open(nome_arquivo, FILE_WRITE);//Abri, ou cria, o arquivo que será gravado.
  // se abrir o arquivo, vai gravar no mesmo os dados que foram coletados
  if (myFile) {
    Serial.print(F("Writing to test.txt...")); //Para uso do programador, será retirado mais afrente.
    myFile.println(F("---------------------------------------------------------------------"));
    myFile.println(F(" "));
    myFile.print(F("Setor: "));
    myFile.print(setor);
    myFile.print(F("         Hora:  "));
    myFile.print(hora2);
    myFile.print(F(":"));
    myFile.println(minuto2);
    myFile.print(F("Data: "));
    myFile.print(dia2);
    myFile.print(F("/"));
    myFile.print(mes2);
    myFile.print(F("/"));
    myFile.print(ano2);
    myFile.print(F("          Peso: "));
    myFile.print(peso);
    myFile.println(F(" Kg"));
    myFile.println(F(" "));
    myFile.println(F("---------------------------------------------------------------------"));
    myFile.close();//fecha o arquivo
    
//    digitalWrite(4,HIGH);
//    digitalWrite(10,LOW);
    //Para uso do programador, será retirado mais afrente.
  } 
  else {
    // Se o arquivo não abrir imprime um erro na serial, debug
    lcd.print(F("Erro no SD"));
    delay(2000);
  }
  

     pegar_codigo=4;
     lcd.clear();
}

And it happens only some times, its not all the times.

Thanks again, and i hope you guys can help me.