Avoid leaving an empty file behind if encode croaks.