in reply to foreach not doing what I expect it to be doing

Aside from what revdiablo said you should note that you rewriting the file each time you iterate the foreach loop.
use
open(DEBUG, ">>bucket.txt");
instead (note de two '>>').
This way you will be appending Dumper results to the file instead of rewriting it.
Data::Dumper is your friend (c:
I use a lot.