Just because you don’t go beyond the 6 months usually given for visitors when entering the US and your family are legal immigrants, doesn’t mean that you can come and go frequently. This is seen as abusing the tourist visa and using it to essentially live in the US. If you have been visiting too often with too little time between visits and are also suspected of working (which is a fair assumption- if you have work then you can’t take off that much and working online in the US on a tourist visa isn’t allowed), this questioning isn’t surprising and was bound to happen.
Yes, they can absolutely confiscate your phone, laptop, go through your belongings, etc. Asking tough questions is not harassment. Suggesting they could have touched you is extreme. Everything is recorded and there are other officers around.
Sorry but you don’t have options here. You’re not a US citizen where you are guaranteed entry and can continue coming back and forth. Even US citizens and permanent residents get pulled into secondary and questioned. My husband who is a US citizen was questioned extensively after a long overseas visit (he spent 2 hours in there). Visiting is a privilege and you’re treating it as a right. It isn’t unfortunately. You’re fortunate they didn’t revoke your visa on the spot and send you back on the next flight out. I strongly advise you to leave when they told you to leave and not visit the US for a long time if you want to keep the privilege of possessing a tourist visa.