Full code review

Change variable names from "p" , "s" to outputFileName and textToOutput or smthg similar. Do the same everywhere else in your code please. Readability is very important for future use of this code.