Compiling problem

Well the compiler is giving you a huge hint of the pb.
Compiler believes that you use myFile as a type. So the error is when you have a line that could be a declaration of something starting with myFile.

Looking quickly you see that there is one place like this:

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

Why would the compiler thinks this? Because You have a closing } just above that ends the setup()...

If the compiler error was not obvious to you (im pretty sure it was also telling you which line was bogus) You would find this easily if you indented your code properly - hit ctrl-T in the IDE