improving codes to write key value pair to .properties file