changed the while loop logic in SaveFileToDocumentDir to match the new isValidPath method