problem with loops and voids and saving outputs in a SD card

But you're not calling it.
What are you trying to do?
Tells us that, not how you think you ought to do it