What drives bacteria to produce a biofilm?

What drives bacteria to produce a biofilm?