Write the file with proper extension.