Measurement of the charm fragmentation function in D* photoproduction at HERA