Are you a consultant or an employee?
While you describe yourself as a consultant (contractor) the description of your role strongly indicates that you are an employee. If the answers to most of the following questions are not a clear "yes", you are probably an employee:
- Can you choose where and when you work?
- Do you get paid for results rather than by the hour?
- Can you pay someone else to do your work for you?
- Do you have other clients at the same time?
- Can you make a profit or a loss?
Contractors can indemnify their principal; employees can't indemnify their employer
An individual who breaches copyright is liable for the breach. However, in commercially produced software, the copyright owner is far more likely to sue the publisher than an individual programmer who worked on the software because they will have more money (probably) to settle the claim.
If the copyright violation was done by an employee in the course of their employment they can be disciplined but they cannot be made to pay for the breach. An employee would also be covered under the employer's Professional Indemnity insurance if they were directly sued.
An independent contractor can, if the contract so provides, indemnify their principal which means that if the principal loses the case, the contractor pays. Contractors need their own PI insurance.
Your specific questions
If I write custom code for a specific functionality, and that ends up being very similar to a third party implementation, and I’m unaware of any such overlap, then does this constitute as an infringement of their IPR?
No. However, that doesn't mean that the third party can't sue you based on their belief that you did copy it. They might even win depending on the evidence.
And if a third party ends up raising a concern around infringement, am I liable for the damages sought by them?
If they prove that you infringed, yes. If you win in court, no; you will still be out time and money even if you win.
Or can I claim that the piece of software is absolutely original since I wrote it myself from scratch?
You can claim whatever you like - the Earth is flat, Donald Trump is the USA's best/worst President, the world is secretly controlled by lizards etc. Courts don't care what you "claim" only what you can prove with evidence. What evidence are you going to present to prove your work is original?
Any tips are welcome!
Make sure you are covered by insurance. If you are an employee, make sure your employer's policy covers you. If you are a contractor, make sure you have your own adequate cover.