What are the functions of magnetic bacteria?
You can find a detailed discussion of this topic here.

Magnetic bacteria contain chains of magnetic crystals (magnetite or greigite) which cause the cells to be oriented in a magnetic field.

It was originally proposed that magnetic bacteria use their magnetosomes to ensure that they swim downwards into the sediment (everywhere on earth, except at the equator, these lines of force have a downward component vector.) However, the current view is more complex than this: magnetic bacteria are microaerophilic and occur in stratified aquatic environments (i.e. ones where there are zones of oxygen concentration at different depths). In this view the magnetic "sense" is not a true taxis, but rather is used to keep the cells oriented in the magnetic field while they adjust their position by sensing oxygen (aerotaxis). As you may be aware, the standard way that Gram-negative bacteria operate is to perform a biassed random walk in three dimensions. The alignment of cells with the magetic field will reduce the dimensionality of the movement, which is more efficient.