If you only want to write and not store the new string, then you can use do the following. Simply replace the space character with a newline character! The newly created string will thus be in the exact format you want it to be written to the file.
String orignalString = readFromFile(...); // implement this
String stringToWriteToFile = originalString.replace(" ","\n"); // so you replace the space with a \n
writeToFile(stringToWriteToFile); // implement this
This will work only if the strings are consistently separated by a single space.
Note: If this is homework, everybody will use String.split(). So you might get a few extra points for being innovative and using String.replace(). I did myself!