Automatically write credentials to file