Only just seen this, but you probably want to have a read of this:
It has an updated version of the code and also tries to make you question why you are downloading files in the first place, usually you don’t need to.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/9In6CPPsqTIJ.