Write to temp file then rename
Escape special characters. Clean up input