Skipping redundant lines before writing to file