Since the part where the costs and stuff is updated is so if-dense and while-dense, I've decided to take some advice from Perlmonks and try to turn some of it into subs.
The whiteboard helps immensely with this stuff, so I'm trying to do it on there first. It's slow but it's doable.
The kludgey way I was doing it before was actually *wiping the whole stock file*. I'm thinking that was my opening of the filehandle, and when I checked in Programming Perl, it said that was the case; I was using >filename, and not writing it properly. Every time I loaded the page, the stock file vanished. Mystery solved through judicious use of the search engine that came with Bookshelf 2.