write credentials csv in more robust way