So, on a principle level your idea has no blunder. It should technically be possible for such an organism to evolve. However, there are multiple issues which i think render this almost impossible.
1. Mechanics
You mention the organism would absorb magnetite and use that to build a primitive magnetic generator. On its surface, this seems like a feasible idea. However, issues start arising very quickly.
For a start, how did the life evolve to this complexity for it to be able to make such a generator ? As in, you cant really make such a complex biochemical machine out of primordial soup.

Right, the Motor Proteins in your body were not one of the first evolutionary steps. In the grand scheme of things, deliberately moving biochemical machines are really hard to do. While a rotating bit and a coil might seem easy, (And i might be wrong here) but i do not think there is any biochemical machine in your body that has freely rotating parts in it. So just from that angle, if i am not mistaken, evolving such a Generator is a huge task.
Then there is the question, like what powers the generator ? Remember, someone has to turn the shaft in order for Electricity to be made. So what mechanism turns the shaft ? Where does the energy for that come from ? And i dont mean in a "Hey is there another Protein that swings the shaft". But rather, at the root of this process where does the Creature get the energy needed from ? Because it better not be Photosynthesis.
2. Roots and Boots
When you take a look at Earth, you might notice there is a lot of Green stuff around. While there is noticeably less moving stuff around. Right there are a lot more trees than animals (In terms of Biomass). The reason for this is very simple.

On average, every m² of ground on Earth gets 1300 Watt of solar energy. It is this energy which is driving Earths ecology. Look at any, literally any, biological process and look at where each part gets its energy from. At the root of every Energy exchange chain is the Sun. (Human Eats Cow, Cow eats Grass, Grass eats light, light -> Sun). There are some exceptions like cringe creatures on Hydrothermal vents. But even then, you can argue the Sun and Earths core do kind of provide the same thing. What is heat, if not less spicy photons ?
And this is really your issue. Replacing photosynthesis is a very hard ask. Sunlight is virtually everywhere and the evolutionary path to using it does not appear to be super hard. In fact, Algae was probably one of the first lifeforms on Earth.
As i said before, your basic though process is not incorrect. But you fail to see what evolutionary is just going to be easier to do. And even if you can make it work by for example not having Sunlight, where does the energy to drive life no come from ?
Magnets ?
The only real answer i can see to the question i posed is, like a Neutron star or something. But at that point we would be taking about such an unstable world any life evolving would be a mirical. Let alone something this complex.
Conclusion
I dont think what you propose here is really feasible. Not because the core mechanical idea is incorrect. it isnt. But because the path to evolving something like this would be so endlessly complex and filled with better alternatives that it is just hard to see work.
And even if you can evolve it, where does the Energy come from ? In a sense, what you have done here is kick the Can down the road.