"Written from scratch" gets around copyrights but not around patents. In very general terms patents protect the functionality of something while copyrights protect a specific expression that might or might not be functional.
What you deliver might infringe a claim in a patent. Or what you deliver might intent a claim whenever it is executed. Or what you deliver might infringe a claim when used with certain data or certain other bits of software. In this last case you might be ok because your part has many other non-infrging uses, or you might be in trouble because you market your product specifically for an infringing use. The wording of a claim in question is key. You might infringe directly or might contribute to you customer's infringement. Or you might induce your customer's infringement. Or you might be fine.