If you implement it from fresh then it is a new program. What matters is what your contract says about what you produce - some contracts pay claim to anything you make even outside of working hours.
Also if you rewrite it, while technically it is a fresh project if there are substantial similarities in how you implement it there could be an argument made that you have reused code that belongs to the company. Even if that is technical false it could be something you'd have to defend sometime in the future. As others have said, implementing the program in a different language and using a different methodology wherever possible should help protect against that.
I think the advice others have given that you should review your contract with a lawyer is sound even if this will be FOSS. It's mainly about ensuring you don't inadvertently open yourself to potential legal repercussions down the line, even if your employers at the moment seem benign. If you do work for a company that lays claim to everything you produce even in your off hours then I would strongly recommend you consider leaving or an exit plan, particularly if you are the sort of person who would be working on your own projects for fun or even your own business ventures.