This helped me better diagnose the problem, though I'm still not sure what the solution would be. The problem is that when I specify dim, typically dim=10, that creates an index with dimension 2*dim+1=21. Then, when that siteset is read back in, the code believes it's reading in an index with dim=21, and proceeds to try to access entries in s from 1 to 2*21+1.
So, long story short, my code might need some serious surgery in order to be able to use the read and write functions?