Refactored write_to_fstab method.