Your use of PB_BODY_SNDIDONLY doesn't make sense to me. You're using it as at least two different things:
a format name: $~ = PB_BODY_SNDIDONLY
a filehandle: open(PB_BODY_SNDIDONLY
Can you include a snippet showing the format you're using??
Something like:
format PB_BODY_SNDIDONLY = ...
Also, you should be aware that once a format is associated with a filehandle, it keeps the association; you don't have to set it repeatedly, such as in your first while.
Unfortunately your code sample doesn't have the right details to answer your question....