create directory if it doesn't exist when trying to get a unique filename from it