1. How have you decided the USB stick shows some bad sectors?
2. What specific malfunction have you noticed in the USB port and how?
Well I am just curious. I am not a programming expert but what all I understand is that you are trying to create a sort of template of a fixed size and perhaps a fixed location ( whether logical or physical I do not know) for your file-writing (embedding). Beyond that it is all greek and latin to me

and so I will not enter into it.
However as I had indicated in my previous post, in a flash storage device (e.g. USB stick, SD-Card), the flash controller implements a flash translation layer, so there is no actual correspondence of logical sectors and physical memory sectors. Bad flash sectors should be sorted out by the flash controller and remapped into the reserve sectors. So you will not come to know of the bad sectors in normal usage. And that is why my first question.
As far as the second question is concerned, it is well known that on some computers the files written on flash drives plugged into the front ports may become corrupt due to most probably interference in the cable. So I have been thinking whether this is the one you are referring to or experiencing.
You are doing some experimentation/trial. Then my intuition tells that
1.You should in the first instance use a known-to-be good new pen-drrive ( not an old pendrive that has seen many write/ read cycles and prone to develop bad sectors due to aging)
2. You should rather use the rear ports on the motherboard and not the front ports.
EDIT: Always format your flash drive with SD Formatter.
https://www.sdcard.org/downloads/formatter_3/