Does it not adjust properly for a new line? If your using 2 tile height it ends up 1 row too high?I doubt it is random. It could try to adjust for both height and width and end up too low. Then again there are any number of things going wrong that I can't guess because I have no idea how it is coded.
It only fails to adjust to new line. Even if I use 10*10-sized enemy, as long as all animation frames in set are placed in one row, the function works fine.