ensure directory exists before creating file

Change-Id: Ic0b929748a3fa7bc2fd4f345343a1d02881a7fa2