make sure object is a str before writting out. This can happen occasionally with PData objects on images