Can another pilot act as my safety pilot for only part of a flight?
Yes. This is all perfectly in accordance with the regulations.
You personally conducted the IFR flying through IMC, as an instrument rated pilot on a filed IFR flight plan. Check.
You cancelled the IFR flight plan midflight with a plan to continue VFR. Check.
In VMC, your VFR-rated pilot friend assumes the responsibility of acting as safety pilot while you undertake practice IFR approaches in simulated IFR. Check.
When logging the time, you would log the total time as PIC for yourself. Your friend was acting as a necessary crew member, but NOT necessarily as PIC. Nevertheless, his name and certificate number should be logged in your book as well. You would record the portion of your flight that was through IMC as ‘actual IFR time’ and your time under the hood as ‘simulated IFR time’. You would record your practice approaches and count them toward your required six-in-six as long as they were performed according to the required standards.
I found this article at Pilot Workshops that can provide you with more detail.
Clear skies!