Corrupted files and folders made by SD module

Hello, I've made this code for writing and reading from a .txt file from my sd card, but the thing is that it doesn't really work. It stops at the SD.begin() if statement most of the times and when i look on my computer at the files inside the sd card they are corrupted and looked like this: └0 .Ç└.
I connected the cs pin both to pin 10 and pin 4 but it's the same thing. Please help!

#include <SD.h>
#include <SPI.h>

void setup() {
  Serial.begin(9600);
  pinMode(10, OUTPUT);
  digitalWrite(10, HIGH);

  if(!SD.begin(10)){
    Serial.println("SD fail");
    return;
  }

  if(SD.exists("test.txt"))
    SD.remove("test.txt");

  File file = SD.open("test.txt", FILE_WRITE);

  if(file)
    file.println("Hello");
  else{
    Serial.println("File fail");
    return;
  }
   
  file.close();

  file = SD.open("test.txt");
  Serial.println("CITIRE:");

  while(file.available())
    Serial.write(file.read());

  file.close();
  Serial.println("Gata");  
}

void loop() {
  // put your main code here, to run repeatedly:

}

Great but what did you write the code for. I have lots of parts that have both a pin 10 and a pin 4.

If this has something to do with an Arduino post an annotated schematic showing exactly how you wired it and how you are powering it.

Not enough information, but results like this can arise from connecting a 5V Arduino to a 3.3V SD module without logic level shifters, and the SD card can even be destroyed.

Please read and follow the instructions in the "How to get the best out of this forum" post, linked at the head of every forum category.

The code is made purely for testing the sd reader and when i read on the sd card on computer after running this program i see folders and files corrupted. And i was saying that i tried the program both by connecting the cs pin to pin 10 and to pin 4, separately

The module has two Vcc ports, one for 3.3V and one for 5V so i was thinking that it will be ok to connect to the 5V port. Is it a chance that i broke the module?

The problem arises when you connect 5V I/O pins to 3.3V I/O pins. A voltage level shifter is required, for example this one.