Updated with code to write files into date-specific directory